import Vue from "vue";
import VueRouter from "vue-router";

import Login from "views/login/Login";
import Layout from "views/layout/Index";

Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    redirect: "/login"
  },
  {
    path: "/home",
    name: "Home",
    component: Layout
  },
  {
    path: "/login",
    name: "Login",
    component: Login
  },
  {
    path: "/shop",
    component: Layout,
    redirect: "/shop/list",
    name: "Shop",
    meta: {
      title: "店铺管理",
      icon: "el-icon-s-help"
    },
    children: [
      {
        path: "create",
        name: "CreateShop",
        meta: { title: "创建店铺", icon: "edit", activeMenu: "/shop/create" }
      },
      {
        path: "edit/:id(\\d+)",
        component: () => import("views/shop/edit"),
        name: "EditShop",
        meta: { title: "编辑店铺", noCache: true, activeMenu: "/shop/detail" }
      },
      {
        path: "list",
        component: () => import("views/shop/list"),
        name: "ShopList",
        meta: { title: "商品列表", icon: "list", activeMenu: "/shop/list" }
      }
    ]
  },
  {
    path: "/food",
    component: Layout,
    redirect: "/food/list",
    name: "Food",
    meta: {
      title: "菜谱管理",
      icon: "el-icon-s-help"
    },
    children: [
      {
        path: "create",
        component: () => import("views/food/create"),
        name: "CreateFood",
        meta: { title: "创建菜谱", icon: "edit", activeMenu: "/food/create" }
      },
      {
        path: "edit/:id(\\d+)",
        component: () => import("views/food/edit"),
        name: "EditFood",
        meta: { title: "编辑食谱", noCache: true, activeMenu: "/food/list" }
      },
      {
        path: "list",
        component: () => import("views/food/list"),
        name: "FoodList",
        meta: { title: "食谱列表", icon: "list", activeMenu: "/food/list" }
      }
    ]
  }
];
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  console.log(location, "----location");
  return originalPush.call(this, location).catch(err => err);
};
const route = new VueRouter({
  mode: "history",
  routes
});

export default route;
